$(function() {
    $(".datepicker").datepicker();
    
    $("#add-detail").button({
        icons: {
            primary: "ui-icon-plusthick"
        }
    })
    .click(function() {
//js_detail_ini//
        $( "#dialog-modal" ).dialog( "open" );
    });
            
    $( "#save-invoice" )
    .button({
        icons: {
            primary: "ui-icon-disk"
        }
    })
    .click(function() {
        var detail=new Array(); 
        var pos = 0;
        $("#detail_table > tbody > tr").each(function() {
            detail[pos] = {
            //js_save_detail//
            };
            pos++;
        });
        $.post("save", {
            //js_save_header// items:pos,
            detail : detail
        } ,
        function(data) {
            alert("Succsess");
            window.location = "index"
        });
            
        
    });
            
    //js_detail//

        
    $( "#delete" ).button({
        icons: {
            primary: "ui-icon-closethick"
        },
        text: false
    })
    $("#delete").live('click', function() {

        $(this).parent().parent().remove();        
    });   
            
    $( "#dialog-modal" ).dialog({
        autoOpen: false,
        height: 355,
        width: 350,
        modal: true,
        buttons: {
            "Insert": function() {                
                //addDetail//
                $( "#detail_table tbody" ).append( "<tr>" +
//js_td_detail//
                    "<td><button  id=\"delete\" class=\"ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only\" role=\"button\" aria-disabled=\"false\" title=\"Button with icon only\" style=\"width: 50px;\"><span class=\"ui-icon ui-icon-closethick\"></span><span class=\"ui-button-text\">Button with icon only</span></button></td>" +
                    "</tr>" );                        
                $( this ).dialog( "close" );
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            $( this ).dialog( "close" );
        }
    });
});



